package com.kevin.mapping.script.node.stmt;

import com.kevin.mapping.script.engine.JSONEnv;
import com.kevin.mapping.script.lexer.Token;

public class DoStmt extends Stmt {
    private Stmt condition;
    private Stmt stmt;

    public DoStmt(Token token, Stmt condition, Stmt stmt) {
        super(token);
        this.condition = condition;
        this.stmt = stmt;
    }

    public Stmt getCondition() {
        return condition;
    }

    public void setCondition(Stmt condition) {
        this.condition = condition;
    }

    public Stmt getStmt() {
        return stmt;
    }

    public void setStmt(Stmt stmt) {
        this.stmt = stmt;
    }

    @Override
    public Token execute(JSONEnv env) {
        Object value = condition.getValue(env);
        if (value instanceof Boolean) {
            if ((boolean) value) {
                return stmt.execute(env);
            }
        }

        return null;
    }
}
